package shop.service.impl;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import shop.mapper.SysUserMapper;
import shop.pojo.SysUser;
import shop.service.SysUserService;

import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public SysUser SelectUserByAccountAndPassword(String account, String password) {
        return sysUserMapper.SelectUserByAccountAndPassword(account, password);
    }

    @Override
    public SysUser login(String account, String password) {

        return sysUserMapper.SelectUserByAccountAndPassword(account,password);
    }

    @Override
    public boolean add(SysUser sysUser) {
        boolean flag =false;
        try {
            if(sysUserMapper.add(sysUser)==1){
                flag=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }

        return flag;
    }

    @Override
    public int getUserCount(String queryRealName, Integer queryRoleId) {
        return sysUserMapper.getUserCount(queryRealName, queryRoleId);
    }

    @Override
    public List<SysUser> getUserList(String queryRealName, Integer queryRoleId, Integer pageIndex, int pageSize) {
        return sysUserMapper.getUserList(queryRealName, queryRoleId,pageIndex,pageSize);
    }

    @Override
    public SysUser getUserById(Integer id) {
        return sysUserMapper.getUserById(id);
    }

    @Override
    public SysUser getById(Integer id) {
        return sysUserMapper.getById(id);
    }

    @Override
    public Integer update(SysUser sysUser) {
        return sysUserMapper.update(sysUser);
    }

    @Override
    public List<SysUser> getAllUserCount(SysUser sysUser) {
        return sysUserMapper.getAllUserCount(sysUser);


    }

    @Override
    public List selectUserByAccount(String name) {
        return sysUserMapper.selectUserByAccount(name);
    }

    @Override
    public Integer deleteUserById(Integer userid) {
        return sysUserMapper.deleteUserById(userid);
    }

    @Override
    public boolean userExistsById(Integer userId) {
        if(sysUserMapper.userExistsById(userId)>0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public String updatePassword(Long id, String newPassword) {
        if(sysUserMapper.updatePassword(id, newPassword)>0){
            return "true";
        }else {
            return "false";
        }

    }


}
